package com.cy.pj.common.exception;


import com.cy.pj.common.vo.JsonResult;
import org.apache.shiro.ShiroException;
import org.apache.shiro.authc.LockedAccountException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

public class ServiceException extends RuntimeException{
    private static final long serialVersionUID = -5598865415547474216L;
    public ServiceException(){}
    public ServiceException(String message){
        super(message);
    }
    public ServiceException(Throwable cause){
        super(cause);
    }
    @ExceptionHandler(ShiroException.class)
    @ResponseBody
    public JsonResult doHandleShiroException(ShiroException e){
        JsonResult r = new JsonResult();
        r.setState(0);
        if(e instanceof UnknownAccountException){
            r.setMessage("账户不存在");
        }else if(e instanceof LockedAccountException){
            r.setMessage("账户已被禁用");
        }else if(e instanceof AuthorizationException){
            r.setMessage("没有此操作权限");
        }else{
            r.setMessage("系统维护中");
        }
        return r;
    }

}
